-
-
Notifications
You must be signed in to change notification settings - Fork 342
feat: Add R program to count unique letters in a string #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new R program for counting unique letters in a string and refactors an existing cocktail sort implementation to follow consistent naming conventions. The changes standardize the codebase to use dot notation for variable and function names throughout.
- Adds a new interactive string manipulation program that counts unique letter occurrences
- Refactors the cocktail sort algorithm to use consistent dot notation naming
- Simplifies code structure and removes redundant comments in the sorting algorithm
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| string_manipulation/unique.letters.count.R | New R script that prompts for user input and counts unique letters in cleaned strings |
| sorting_algorithms/cocktail_sort.r | Refactored to use dot notation naming and simplified code structure |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| input.string <- readline(prompt = "Enter a string: ") | ||
|
|
||
| # Convert to lowercase and remove non-letter characters | ||
| clean.string <- tolower(gsub("[^a-z]", "", input.string)) |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern [^a-z] will remove uppercase letters before tolower() is applied. This should be [^a-zA-Z] to preserve all letters before converting to lowercase, or the order should be reversed to apply tolower() first.
| clean.string <- tolower(gsub("[^a-z]", "", input.string)) | |
| clean.string <- tolower(gsub("[^a-zA-Z]", "", input.string)) |
| unique.letters <- unique(letters.vec) | ||
|
|
||
| # Count occurrences of each unique letter | ||
| letter.counts <- table(letters.vec) |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table() function is called on letters.vec but only values from unique.letters are accessed. This creates unnecessary computation for letters that won't be displayed. Consider using letter.counts <- table(letters.vec)[unique.letters] or iterating directly over the table results.
| letter.counts <- table(letters.vec) | |
| letter.counts <- table(letters.vec)[unique.letters] |
| # Display results | ||
| cat("Unique letters and their counts:\n") | ||
| for (letter in unique.letters) { | ||
| cat(letter, ":", letter.counts[letter], "\n") |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table() function is called on letters.vec but only values from unique.letters are accessed. This creates unnecessary computation for letters that won't be displayed. Consider using letter.counts <- table(letters.vec)[unique.letters] or iterating directly over the table results.
|
Please check comments |
This PR adds a new R script
unique.letters.count.Rthat:Variable names use dots (.) instead of underscores to follow the naming style preference.
Example:
Input: "Hello World!"
Output:
h : 1
e : 1
l : 3
o : 2
w : 1
r : 1
d : 1